<?php

use yii\helpers\Url;
use yii\helpers\Html;
use website\helpers\Render;
use common\models\User;
use common\models\UserCollection;
use common\models\Employment;

$this->addCrumbs('我的收藏');
$this->title = '简历收藏';
?>
<style>
    #info-table {padding:10px;}
    #info-table .designer-detail .panel {position:relative;padding:20px 10px;margin:5px;border-radius:5px;}
    #info-table .designer-detail .header {height:50px;line-height:25px;border-bottom:none;}
    #info-table .designer-detail .imager img {width:50px;height:50px;margin-right:20px;}
    #info-table .designer-detail .username {font-size:16px;}
    #info-table .designer-detail .bodyer {line-height:30px;padding-right:80px;font-size:12px;}
    #info-table .designer-detail .into {top:50px;width:90px;}
    #info-table .designer-detail .into-ensume {line-height:22px;border-radius:3px;}
    #info-table .designer-detail .delete-data {position:absolute;top:10px;right:10px;display:none;}
    #info-table .designer-detail .panel:hover .delete-data {display:block;}
</style>

<div class="contenter">
    <?= $this->render('/user/navigator', ['active' => 'collection-designer-list']) ?>
    
    <div id="user-contenter">
        <div class="box-shadow pb-20px" id="sub-contenter">
            <div class="data-title"><span class="h3"><?= $this->title ?></span></div>
            <div class="clear" id="info-table">
                <div class="designer-detail"><i class="icon-search"></i> 数据加载中，请稍后.</div>
            </div>
            <div class="flyer-page mt right" id="info-page">
                <div class="html mr-10px"></div>
            </div>
        </div>
    </div>
</div>
<div id="search" style="display:none;">
    <?= Render::select('style', \common\models\Design::$styleSelector, null) ?>
    <select id="category"></select>
</div>

<script src="<?= Render::static('art-template/template.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tabler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tableHandler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/categorier.class.js') ?>"></script>
<script src="<?= Render::static('system/category-design.data.js') ?>"></script>
<script>
    var categorierClass = new categorier();
    $(document).ready(function() {
        categorierClass.init({ fix: false, dom: '#category', data: DesignCategories, relate: DesignCategoriesRelation, start: '<?= Yii::$app->params['designCategories'] ?>' });
        // 初始化表格异步加载事件
        (new tabler).init({
            // 请求地址
            url: '<?= Url::to('@web/employer/collection-designer-list') ?>',
            // 数据渲染配置
            table: '#info-table', page: '#info-page', template: 'info-template', search: '#info-search', readyCall: true,
            // param => tabler
            afterPost: function(param) {
                // 名称显示
                tableHandler.renderCategory({ category: $(param.tabler).find('.styles'), select: '#search select[name=style]', color: false, splite: '，', default: '--' });
                tableHandler.renderCategory({ category: $(param.tabler).find('.categories'), color: false, splite: '，', default: '--', functionName: function(id) {
                    return categorierClass.renderTitles(id);
                }});
                // 初始化 删除按钮事件
                tableHandler.requestSingle({
                    button: $(param.tabler).find('.delete-data'), url: "<?= Url::to('@web/user/collection') ?>", isConfirm: true, trKey: '.designer-detail',
                    beforePost: function(params) {
                        params.data = { handle: $(params.mthis).attr('data-handle'), id: $(params.tr).attr('data-id'), type: '<?= UserCollection::TypeDesigner ?>' };
                    },
                    requestSuccess: function(params) {
                        if($(params.mthis).attr('data-handle') == 'collection') {
                            $(params.mthis).attr('data-handle', 'revoke').html('取消收藏');
                        }
                        else {
                            $(params.mthis).attr('data-handle', 'collection').html('加入收藏');
                        }
                    }
                });
            }
        });
    });
</script>
<script id="info-template" type="text/html">
    {{if infos != undefined && infos.length}}
    {{each infos as info key}}
    <div class="designer-detail boxing" id="tr-{{info.collection_id}}" data-id="{{info.collection_id}}">
        <div class="panel">
            <div class="header">
                <div class="imager"><img src="<?= Render::upload('{{designer[info.collection_id].photo}}') ?>"></div>
                <div class="user">
                    <h3 class="username">{{designer[info.collection_id].nickname}}</h3>
                    <p class="star cl-red">{{designer[info.collection_id].star | star}}</p>
                </div>
            </div>
            <div class="bodyer">
                <p>类目：<span class="categories">{{designer[info.collection_id].categoriesString}}</span></p>
                <p>风格：<span class="styles">{{designer[info.collection_id].stylesString}}</span></p>
                <p>软件：{{designer[info.collection_id].skills}}</p>
                <div class="into">
                    <p>薪资：{{designer[info.collection_id].salary / 100 | fmoney}}元</p>
                    <p><a class="into-ensume" href="<?= Url::to('@web/seer/resume?id={{info.collection_id}}') ?>">进入简历 &gt;</a></p>
                </div>
            </div>
            <button class="delete-data flyer-button normal border-round narrow thin" data-handle="revoke">取消收藏</button>
        </div>
    </div>
    {{/each}}
    {{else}}
    <div class="pd-10px"><i class="icon-ban-circle"></i> 您还没有任何简历收藏信息！</div>
    {{/if}}
</script>